import Mock from 'mockjs'
import { getQueryAll, getCurrentList, detailFunc, filterList, getListResult } from '@/api/mock/utils'
import { addFunc, deleteFunc, editFunc } from '../utils'



import Mock from 'mockjs'

const { userList, applicationList, messageList, messageStatusList } = Mock.mock({
    'userList|15-35': [
        {
            id: '@increment(1)',
            username: '@name',
            nickName: '@cname',
            'accountType|1-4': 1,
            'enabled|0-1': 1,
            'deleted|0-1': 1,
            'accountType|1-4': 1,
            email: '@email',
            mobile: '@phone',
            createTime: '2014-03-25T06:26:01.927Z',
            updateTime: '2014-03-25T06:26:01.927Z'
        }
    ],
    'applicationList|15-100': [
        {
            id: '@increment(1)',
            name: '@cword(3)',
            description: '@sentence(5)',
            'enabled|0-1': 1,
            adminConsoleUrl: '@url',
            createTime: '2014-03-25T06:26:01.927Z',
            updateTime: '2014-03-25T06:26:01.927Z'
        }
    ],
    'messageList|15-100': [
        {
            id: '@increment(1)',
            title: '@cword(3)',
            creator: '@cname',
            content: '@csentence(50)',
            'enabled|0-1': 1,
            creationDatetime: '2014-03-25T06:26:01.927Z',
        }
    ],
    'messageStatusList|15-100': [
        {
            id: '@increment(1)',
            title: '@cword(3)',
            receiver: '@cname',
            content: '@csentence(50)',
            'readStatus|0-1': 0,
            'enabled|0-1': 1,
            readDatetime: '2014-03-25T06:26:01.927Z',
        }
    ]
})

// 列表
Mock.mock(/\/list/, 'get', ({ url }) => {
  try {
      const{ username, nickName, createTime, pageNum, pageSize } = getQueryAll(url)
      
      let list = filterList(userList, { username, nickName, createTime })
      list = getCurrentList(list, parseInt(pageNum), parseInt(pageSize))
      return getListResult(list, userList.length)
  } catch(err) {
      console.error(err)
  }
  
})
